﻿using Microsoft.AspNetCore.Mvc;
using SIMS.Shared.DTO;
using SIMS.WebApi.Models;
using SIMS.WebApi.Services.Classes;

namespace SIMS.WebApi.Controllers
{
    /// <summary>
    /// 班级控制器
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class ClassesController : ControllerBase
    {
        private readonly ILogger<ClassesController> logger;

        private readonly IClassesAppService _service;

        public ClassesController(ILogger<ClassesController> logger, IClassesAppService service)
        {
            this.logger = logger;
            this._service = service;
        }

        /// <summary>
        /// 获取班级信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        public IActionResult GetClasses(int id)
        {
            var data = _service.GetClasses(id);
            
            var res = new ResultModel();
            res.code = 1;
            res.msg = "success";
            res.data = data;
            return Ok(res);
        }

        /// <summary>
        /// 获取班级列表
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        public IActionResult GetClassess(string? dept, string? grade, int pageNum, int pageSize)
        {
            var data = _service.GetClassess(dept, grade, pageNum, pageSize);

            var res = new ResultModel();
            res.code = 1;
            res.msg = "success";
            res.data = data;
            return Ok(res);
        }

        /// <summary>
        /// 新增班级
        /// </summary>
        /// <param name="classes"></param>
        /// <returns></returns>
        [HttpPost]
        public IActionResult AddClasses(ClassesDTO classes)
        {
            var data = _service.AddClasses(classes);

            var res = new ResultModel();
            res.code = 1;
            res.msg = "success";
            res.data = data;
            return Ok(res);
        }

        /// <summary>
        /// 修改班级
        /// </summary>
        /// <param name="classes"></param>
        /// <returns></returns>
        [HttpPut]
        public IActionResult UpdateClasses(ClassesDTO classes)
        {
            var data = _service.UpdateClasses(classes);

            var res = new ResultModel();
            res.code = 1;
            res.msg = "success";
            res.data = data;
            return Ok(res);
        }

        /// <summary>
        /// 删除班级
        /// </summary>
        /// <param name="id"></param>
        [HttpDelete]
        public IActionResult DeleteClasses(int id)
        {
            var data = _service.DeleteClasses(id);

            var res = new ResultModel();
            res.code = 1;
            res.msg = "success";
            res.data = data;
            return Ok(res);
        }
    }
}
